Load data - LOW CONCENTRATION

raw <- 
  bind_rows(
    read_excel(file.path("data", "20170517low_ND_data_export.xlsx")) 
  ) %>% 
  select(File, Nr., Start, Rt, End, # filename and retention times
         Ampl44=`Ampl 44`, Ampl45=`Ampl 45`, # amplitudes
         Area44=`rIntensity 44`, Area45=`rIntensity 45`, # areas
         Intensity=`Intensity All`, #peak intensities
         R13C = `R 13C/12C`, d13C = `13C/12C` # ratio and delta values
  )

Map peaks

### CHANGE MAPPING FILE NAME ###
data_matched <- map_peaks(raw, metadata_file = file.path("metadata", "old_standard_peaks_July20.xlsx"), quiet = FALSE)
## INFO: 408 peaks in 17 files successfully assigned.

Add standard values

standards <- read_excel(file.path("metadata", "gc_irms_indiana_A6.xlsx"))
data_w_stds <- data_matched %>% 
  filter(type == "standard", is_ref_peak == "no") %>% 
  left_join(standards, by = "compound") %>% 
  mutate(is_std = !is.na(true.d13C) | !is.na(true.d2H))

Evaluate standards

Visualize

data_w_stds %>% 
  ggplot() +
  aes(x = true.d13C, y = d13C, color = File) + 
  geom_smooth(method = "lm", se = FALSE, alpha = 0.5) +
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

Overview

std_corrections <- 
  data_w_stds %>% 
  group_by(File) %>% 
  do({
    m <- lm(d13C ~ true.d13C, data = .)
    data_frame(
      offset = coefficients(m)[1],
      slope = coefficients(m)[2],
      delta_ref_CO = -offset/slope,
      max_residual = max(summary(m)$residuals),
      rss = sum(summary(m)$residuals^2),
      r2 = summary(m)$r.squared
    )
  }) 
std_corrections %>% knitr::kable(d = 3)
File offset slope delta_ref_CO max_residual rss r2
1135__170518_A5_PTV_2_0_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 8.125 0.940 -8.642 0.780 3.131 0.955
1136__170518_A5_PTV_2_5_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 9.947 0.994 -10.009 0.635 2.035 0.973
1137__170518_A5_PTV_2_5_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 10.864 1.026 -10.591 0.762 1.260 0.984
1138__170518_A5_PTV_3_0_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 10.156 1.001 -10.142 0.487 1.475 0.981
1139__170518_A5_PTV_3_0_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 10.718 1.017 -10.536 0.503 1.720 0.978
1140__170518_A5_PTV_3_5_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 10.052 0.995 -10.098 0.418 1.089 0.986
1141__170518_A5_PTV_3_5_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 7.999 0.936 -8.548 0.805 5.296 0.926
1142__170518_A5_PTV_4_0_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 8.270 0.932 -8.875 0.630 5.521 0.922
1143__170518_A5_PTV_4_0_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 10.814 1.015 -10.649 0.467 0.842 0.989
1144__170518_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 10.407 1.002 -10.388 0.384 0.782 0.990
1145__170518_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 10.578 1.010 -10.473 0.378 1.557 0.980
1146__170518_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 9.901 0.983 -10.075 0.654 2.645 0.965
1147__170518_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 17.261 1.348 -12.800 1.158 8.650 0.941
1148__170518_A5_PTV_5_5_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 10.551 1.011 -10.438 0.826 1.292 0.984
1149__170518_A5_PTV_5_5_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 9.863 0.982 -10.046 1.509 3.632 0.953
1150__170518_A5_PTV_6_0_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 12.084 1.086 -11.131 1.139 3.288 0.964
1151__170518_A5_PTV_6_0_A5dilutionsTest_CO2_newVial_1_4ng@ul.dxf 9.300 0.968 -9.603 0.382 0.715 0.990

isotope values check by rentention time

data_w_stds %>% 
  ggplot() +
  aes(x = Rt, y = d13C, color = File) + 
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

ggplotly(ggplot2::last_plot() + theme(legend.position = "none"))

peak intensities check by rentention time

data_w_stds %>% 
  ggplot() +
  aes(x = Rt, y = Intensity, color = File) + 
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

ggplotly(ggplot2::last_plot() + theme(legend.position = "none"))

Load data - HIGH CONCENTRATION

raw <- 
  bind_rows(
    read_excel(file.path("data", "20170519high_ND_data_export.xlsx")) 
  ) %>% 
  select(File, Nr., Start, Rt, End, # filename and retention times
         Ampl44=`Ampl 44`, Ampl45=`Ampl 45`, # amplitudes
         Area44=`rIntensity 44`, Area45=`rIntensity 45`, # areas
         Intensity=`Intensity All`, #peak intensities
         R13C = `R 13C/12C`, d13C = `13C/12C` # ratio and delta values
  )

Map peaks

### CHANGE MAPPING FILE NAME ###
data_matched <- map_peaks(raw, metadata_file = file.path("metadata", "old_standard_peaks_high_July20.xlsx"), quiet = FALSE)
## INFO: 600 peaks in 25 files successfully assigned.
## WARNING: 68 peaks are unassigned or missing
## # A tibble: 68 × 22
##                                                              File   Nr.
##                                                             <chr> <dbl>
## 1  1175__170520_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf    12
## 2  1175__170520_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf    14
## 3  1175__170520_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf    16
## 4  1175__170520_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf    18
## 5  1175__170520_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf    20
## 6  1175__170520_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf    22
## 7  1177__170520_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf    10
## 8  1177__170520_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf    12
## 9  1177__170520_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf    14
## 10 1177__170520_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf    16
## # ... with 58 more rows, and 20 more variables: Start <dbl>, Rt <dbl>,
## #   End <dbl>, Ampl44 <dbl>, Ampl45 <dbl>, Area44 <dbl>, Area45 <dbl>,
## #   Intensity <dbl>, R13C <dbl>, d13C <dbl>, compound <chr>,
## #   is_ref_peak <chr>, map <chr>, Rt_target <dbl>, type <chr>,
## #   process <chr>, notes <dbl>, depth <dbl>, n_matches <dbl>,
## #   n_overlapping <dbl>

Add standard values

standards <- read_excel(file.path("metadata", "gc_irms_indiana_A6.xlsx"))
data_w_stds <- data_matched %>% 
  filter(type == "standard", is_ref_peak == "no") %>% 
  left_join(standards, by = "compound") %>% 
  mutate(is_std = !is.na(true.d13C) | !is.na(true.d2H))

Evaluate standards

Visualize

data_w_stds %>% 
  ggplot() +
  aes(x = true.d13C, y = d13C, color = File) + 
  geom_smooth(method = "lm", se = FALSE, alpha = 0.5) +
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

Overview

std_corrections <- 
  data_w_stds %>% 
  group_by(File) %>% 
  do({
    m <- lm(d13C ~ true.d13C, data = .)
    data_frame(
      offset = coefficients(m)[1],
      slope = coefficients(m)[2],
      delta_ref_CO = -offset/slope,
      max_residual = max(summary(m)$residuals),
      rss = sum(summary(m)$residuals^2),
      r2 = summary(m)$r.squared
    )
  }) 
std_corrections %>% knitr::kable(d = 3)
File offset slope delta_ref_CO max_residual rss r2
1158__170519_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 7.202 0.874 -8.236 1.091 3.311 0.946
1159__170519_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 5.488 0.861 -6.377 1.054 5.390 0.912
1160__170519_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 6.220 0.876 -7.101 0.593 2.633 0.957
1161__170519_A5_PTV_1_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 8.181 0.927 -8.824 0.408 0.917 0.986
1162__170519_A5_PTV_1_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 9.337 0.971 -9.616 0.715 1.412 0.981
1163__170520_A5_PTV_1_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 9.376 0.968 -9.689 0.446 0.845 0.988
1164__170520_A5_PTV_1_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 10.678 1.010 -10.572 0.580 1.859 0.976
1165__170520_A5_PTV_2_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 9.975 0.984 -10.137 0.241 0.445 0.994
1166__170520_A5_PTV_2_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 7.723 0.914 -8.449 0.637 1.174 0.982
1167__170520_A5_PTV_2_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 9.711 0.973 -9.985 0.308 1.728 0.976
1168__170520_A5_PTV_2_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 9.389 0.968 -9.702 0.333 1.574 0.978
1169__170520_A5_PTV_3_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 9.682 0.979 -9.894 0.546 4.359 0.943
1170__170520_A5_PTV_3_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 8.862 0.955 -9.279 0.617 5.559 0.925
1171__170520_A5_PTV_3_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 9.065 0.962 -9.423 0.615 5.869 0.923
1172__170520_A5_PTV_3_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 9.135 0.963 -9.488 0.561 4.981 0.934
1173__170520_A5_PTV_4_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 9.245 0.966 -9.570 0.684 4.796 0.936
1174__170520_A5_PTV_4_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 9.925 0.988 -10.042 0.645 4.462 0.943
1175__170520_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 10.762 1.002 -10.738 0.412 0.727 0.991
1176__170520_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 10.604 0.996 -10.645 0.329 0.846 0.989
1177__170520_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 11.872 1.038 -11.432 0.766 1.666 0.980
1178__170520_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 10.693 1.002 -10.675 0.592 1.163 0.985
1179__170520_A5_PTV_5_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 11.136 1.021 -10.903 0.310 0.856 0.989
1180__170520_A5_PTV_5_5_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 10.374 0.997 -10.407 0.232 0.677 0.991
1181__170520_A5_PTV_6_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 11.460 1.031 -11.117 0.239 0.306 0.996
1182__170520_A5_PTV_6_0_A5dilutionsTest_CO2_newVial_7ng@ul.dxf 10.699 1.006 -10.640 0.214 0.199 0.997

isotope values check by rentention time

data_w_stds %>% 
  ggplot() +
  aes(x = Rt, y = d13C, color = File) + 
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

peak intensities check by rentention time

data_w_stds %>% 
  ggplot() +
  aes(x = Rt, y = Intensity, color = File) + 
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

ggplotly(ggplot2::last_plot() + theme(legend.position = "none"))

Load data - VERY HIGH CONCENTRATION #1

raw <- 
  bind_rows(
    read_excel(file.path("data", "20170526veryhigh_ND_data_export.xlsx")) 
  ) %>% 
  select(File, Nr., Start, Rt, End, # filename and retention times
         Ampl44=`Ampl 44`, Ampl45=`Ampl 45`, # amplitudes
         Area44=`rIntensity 44`, Area45=`rIntensity 45`, # areas
         Intensity=`Intensity All`, #peak intensities
         R13C = `R 13C/12C`, d13C = `13C/12C` # ratio and delta values
  )

Map peaks

### CHANGE MAPPING FILE NAME ###
data_matched <- map_peaks(raw, metadata_file = file.path("metadata", "old_standard_peaks_veryhigh_July20.xlsx"), quiet = FALSE)
## INFO: 628 peaks in 27 files successfully assigned.
## WARNING: 20 peaks are unassigned or missing
## # A tibble: 20 × 22
##                                                               File   Nr.
##                                                              <chr> <dbl>
## 1  1189__170526_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 2  1190__170526_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 3  1191__170526_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 4  1192__170526_A5_PTV_1_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 5  1193__170526_A5_PTV_1_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 6  1194__170526_A5_PTV_1_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 7  1195__170526_A5_PTV_1_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 8  1196__170526_A5_PTV_2_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 9  1197__170526_A5_PTV_2_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 10 1198__170527_A5_PTV_2_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 11 1199__170527_A5_PTV_2_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 12 1200__170527_A5_PTV_3_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 13 1201__170527_A5_PTV_3_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 14 1202__170527_A5_PTV_3_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 15 1203__170527_A5_PTV_3_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 16 1204__170527_A5_PTV_4_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 17 1205__170527_A5_PTV_4_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 18 1206__170527_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 19 1214__170527_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 20 1215__170527_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## # ... with 20 more variables: Start <dbl>, Rt <dbl>, End <dbl>,
## #   Ampl44 <dbl>, Ampl45 <dbl>, Area44 <dbl>, Area45 <dbl>,
## #   Intensity <dbl>, R13C <dbl>, d13C <dbl>, compound <chr>,
## #   is_ref_peak <chr>, map <chr>, Rt_target <dbl>, type <chr>,
## #   process <chr>, notes <dbl>, depth <dbl>, n_matches <dbl>,
## #   n_overlapping <dbl>

Add standard values

standards <- read_excel(file.path("metadata", "gc_irms_indiana_A6.xlsx"))
data_w_stds <- data_matched %>% 
  filter(type == "standard", is_ref_peak == "no") %>% 
  left_join(standards, by = "compound") %>% 
  mutate(is_std = !is.na(true.d13C) | !is.na(true.d2H))

Evaluate standards

Visualize

data_w_stds %>% 
  ggplot() +
  aes(x = true.d13C, y = d13C, color = File) + 
  geom_smooth(method = "lm", se = FALSE, alpha = 0.5) +
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

Overview

std_corrections <- 
  data_w_stds %>% 
  group_by(File) %>% 
  do({
    m <- lm(d13C ~ true.d13C, data = .)
    data_frame(
      offset = coefficients(m)[1],
      slope = coefficients(m)[2],
      delta_ref_CO = -offset/slope,
      max_residual = max(summary(m)$residuals),
      rss = sum(summary(m)$residuals^2),
      r2 = summary(m)$r.squared
    )
  }) 
std_corrections %>% knitr::kable(d = 3)
File offset slope delta_ref_CO max_residual rss r2
1189__170526_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 8.788 0.926 -9.489 0.512 2.092 0.951
1190__170526_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 7.373 0.900 -8.191 0.557 3.560 0.916
1191__170526_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 7.364 0.900 -8.179 0.855 2.941 0.929
1192__170526_A5_PTV_1_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 10.007 0.976 -10.255 0.513 0.663 0.986
1193__170526_A5_PTV_1_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 9.981 0.980 -10.188 0.389 0.724 0.984
1194__170526_A5_PTV_1_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 8.156 0.925 -8.813 0.583 2.349 0.946
1195__170526_A5_PTV_1_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 7.054 0.896 -7.876 0.762 4.822 0.888
1196__170526_A5_PTV_2_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 5.660 0.861 -6.576 1.094 10.148 0.777
1197__170526_A5_PTV_2_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 2.820 0.779 -3.619 1.606 16.809 0.633
1198__170527_A5_PTV_2_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 6.329 0.894 -7.081 1.785 13.947 0.732
1199__170527_A5_PTV_2_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 6.093 0.883 -6.902 1.561 10.851 0.774
1200__170527_A5_PTV_3_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 7.332 0.917 -8.000 0.966 5.586 0.878
1201__170527_A5_PTV_3_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 7.272 0.909 -7.998 0.943 3.954 0.909
1202__170527_A5_PTV_3_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 7.412 0.911 -8.136 0.734 2.420 0.942
1203__170527_A5_PTV_3_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 7.417 0.908 -8.166 0.799 2.717 0.935
1204__170527_A5_PTV_4_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 8.388 0.943 -8.892 0.765 1.907 0.957
1205__170527_A5_PTV_4_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 9.024 0.962 -9.380 0.297 0.713 0.984
1206__170527_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 8.945 0.958 -9.333 0.292 0.451 0.990
1207__170527_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 15.573 1.163 -13.396 1.667 6.861 0.937
1208__170527_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 13.983 1.128 -12.394 1.499 5.706 0.944
1209__170527_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 14.920 1.135 -13.144 1.423 3.911 0.961
1210__170527_A5_PTV_5_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 15.446 1.163 -13.281 1.828 6.813 0.938
1211__170527_A5_PTV_5_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 14.849 1.141 -13.019 1.550 4.852 0.953
1212__170527_A5_PTV_6_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 14.009 1.118 -12.536 1.279 3.969 0.960
1213__170527_A5_PTV_6_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 13.505 1.092 -12.363 1.150 3.144 0.966
1214__170527_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 10.938 1.017 -10.759 1.348 2.937 0.944
1215__170527_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 8.498 0.931 -9.124 0.874 2.632 0.940

isotope values check by rentention time

data_w_stds %>% 
  ggplot() +
  aes(x = Rt, y = d13C, color = File) + 
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

ggplotly(ggplot2::last_plot() + theme(legend.position = "none"))

peak intensities check by rentention time

data_w_stds %>% 
  ggplot() +
  aes(x = Rt, y = Intensity, color = File) + 
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

ggplotly(ggplot2::last_plot() + theme(legend.position = "none"))

Load data - VERY HIGH CONCENTRATION #2

raw <- 
  bind_rows(
    read_excel(file.path("data", "20170601veryhigh_ND_data_export.xlsx")) 
  ) %>% 
  select(File, Nr., Start, Rt, End, # filename and retention times
         Ampl44=`Ampl 44`, Ampl45=`Ampl 45`, # amplitudes
         Area44=`rIntensity 44`, Area45=`rIntensity 45`, # areas
         Intensity=`Intensity All`, #peak intensities
         R13C = `R 13C/12C`, d13C = `13C/12C` # ratio and delta values
  )

Map peaks

### CHANGE MAPPING FILE NAME ###
data_matched <- map_peaks(raw, metadata_file = file.path("metadata", "old_standard_peaks_veryhigh2_July20.xlsx"), quiet = FALSE)
## INFO: 272 peaks in 12 files successfully assigned.
## WARNING: 16 peaks are unassigned or missing
## # A tibble: 16 × 22
##                                                               File   Nr.
##                                                              <chr> <dbl>
## 1  1222__170601_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 2  1222__170601_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 3  1223__170601_A5_PTV_1_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 4  1223__170601_A5_PTV_1_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 5  1224__170601_A5_PTV_1_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 6  1224__170601_A5_PTV_1_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 7  1225__170601_A5_PTV_2_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 8  1225__170601_A5_PTV_2_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 9  1226__170601_A5_PTV_2_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 10 1227__170601_A5_PTV_3_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 11 1228__170602_A5_PTV_3_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 12 1229__170602_A5_PTV_4_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 13 1230__170602_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 14 1231__170602_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 15 1232__170602_A5_PTV_5_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## 16 1233__170602_A5_PTV_6_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf    NA
## # ... with 20 more variables: Start <dbl>, Rt <dbl>, End <dbl>,
## #   Ampl44 <dbl>, Ampl45 <dbl>, Area44 <dbl>, Area45 <dbl>,
## #   Intensity <dbl>, R13C <dbl>, d13C <dbl>, compound <chr>,
## #   is_ref_peak <chr>, map <chr>, Rt_target <dbl>, type <chr>,
## #   process <chr>, notes <dbl>, depth <dbl>, n_matches <dbl>,
## #   n_overlapping <dbl>

Add standard values

standards <- read_excel(file.path("metadata", "gc_irms_indiana_A6.xlsx"))
data_w_stds <- data_matched %>% 
  filter(type == "standard", is_ref_peak == "no") %>% 
  left_join(standards, by = "compound") %>% 
  mutate(is_std = !is.na(true.d13C) | !is.na(true.d2H))

Evaluate standards

Visualize

data_w_stds %>% 
  ggplot() +
  aes(x = true.d13C, y = d13C, color = File) + 
  geom_smooth(method = "lm", se = FALSE, alpha = 0.5) +
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

Overview

std_corrections <- 
  data_w_stds %>% 
  group_by(File) %>% 
  do({
    m <- lm(d13C ~ true.d13C, data = .)
    data_frame(
      offset = coefficients(m)[1],
      slope = coefficients(m)[2],
      delta_ref_CO = -offset/slope,
      max_residual = max(summary(m)$residuals),
      rss = sum(summary(m)$residuals^2),
      r2 = summary(m)$r.squared
    )
  }) 
std_corrections %>% knitr::kable(d = 3)
File offset slope delta_ref_CO max_residual rss r2
1222__170601_A5_PTV_0_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 12.707 1.031 -12.328 1.466 8.469 0.856
1223__170601_A5_PTV_1_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 9.943 0.977 -10.176 0.496 1.546 0.967
1224__170601_A5_PTV_1_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 10.169 0.978 -10.397 0.320 0.438 0.990
1225__170601_A5_PTV_2_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 10.854 1.000 -10.849 0.322 0.491 0.990
1226__170601_A5_PTV_2_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 9.870 0.968 -10.193 1.420 2.402 0.949
1227__170601_A5_PTV_3_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 8.990 0.948 -9.483 0.978 2.961 0.935
1228__170602_A5_PTV_3_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 7.774 0.913 -8.516 1.875 6.934 0.851
1229__170602_A5_PTV_4_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 9.753 0.967 -10.086 1.104 1.679 0.964
1230__170602_A5_PTV_4_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 7.772 0.909 -8.552 0.579 1.093 0.973
1231__170602_A5_PTV_5_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 8.903 0.953 -9.345 1.403 4.105 0.913
1232__170602_A5_PTV_5_5_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 8.402 0.932 -9.012 1.391 4.557 0.901
1233__170602_A5_PTV_6_0_A5dilutionsTest_CO2_newVial_14ng@ul.dxf 8.717 0.950 -9.176 1.146 2.636 0.942

isotope values check by rentention time

data_w_stds %>% 
  ggplot() +
  aes(x = Rt, y = d13C, color = File) + 
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

ggplotly(ggplot2::last_plot() + theme(legend.position = "none"))

peak intensities check by rentention time

data_w_stds %>% 
  ggplot() +
  aes(x = Rt, y = Intensity, color = File) + 
  geom_point() +
  theme_bw() +
  theme(legend.position = "none") 

ggplotly(ggplot2::last_plot() + theme(legend.position = "none"))